﻿/***************************
 * 数据访问层
 * 我的勘察列表展示、修改状态
 * Author：JXL
 ***************************/ 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IDAL;
using Model;
using System.Data;
using System.Data.SqlClient;
using HouseCommon;

namespace DAL
{
   public class prospectDAL:Iprospect
    {
       /// <summary>
       /// 获取数据列表
       /// </summary>
       /// <param name="pageindex"></param>
       /// <param name="pagesize"></param>
       /// <param name="wherestr"></param>
       /// <returns></returns>
       public pagelist<Basic_infoss> getlist(int pageindex, int pagesize, string wherestr,int id)
       {
           string tablename = " Basic_Info a,Department c ";
           string strwhere = " a.the_Department=c.department_Id and a.Survey="+id+"" + wherestr;
           string strid = "a.projectNumber,c.department_Name,a.loan_Contacts,a.loan_ContactsTEL,a.basic_CreateTime,a.house_Located,a.basic_State";
           string sort = "basic_id";
           using (SqlConnection sql = new SqlConnection(HouseCommon.Common.conn))
           {
               sql.Open();
               SqlCommand cmd = new SqlCommand("Common_PageList", sql);
               cmd.CommandType = CommandType.StoredProcedure;
               SqlParameter[] pa ={
                                     new SqlParameter("@tab",SqlDbType.NVarChar,100),
                                     new SqlParameter("@pageindex",SqlDbType.Int),
                                     new SqlParameter("@pagesize",SqlDbType.Int),
                                     new SqlParameter("@pagecount",SqlDbType.Int),
                                     new SqlParameter("@strFld",SqlDbType.NVarChar,500),
                                     new SqlParameter("@strWhere",SqlDbType.NVarChar,500),
                                     new SqlParameter("@Sort",SqlDbType.NVarChar,50)
                                 };
               pa[0].Value = tablename;
               pa[1].Value = pageindex;
               pa[2].Value = pagesize;
               pa[3].Direction = ParameterDirection.Output;
               pa[4].Value = strid;
               pa[5].Value = strwhere;
               pa[6].Value = sort;
               cmd.Parameters.AddRange(pa);
               SqlDataAdapter da = new SqlDataAdapter(cmd);
               DataTable ta = new DataTable();
               da.Fill(ta);
               List<Basic_infoss> list = DBhelper.DBHelper.DataTable2List<Basic_infoss>(ta).ToList();

               pagelist<Basic_infoss> liss = new pagelist<Basic_infoss>();
               liss.getlist = list;
               liss.pagecount = (int)pa[3].Value;
               return liss;
           }

       }

       /// <summary>
       /// 修改为勘察完成
       /// </summary>
       /// <param name="name"></param>
       /// <returns></returns>
       public int ProUptOne(string name)
       {
           using (SqlConnection conn = new SqlConnection(Common.conn))
           {
               conn.Open();
               string sql = string.Format("update Basic_Info set Basic_State=2,survey_EndTime='"+DateTime.Now+"' where ProjectNumber='{0}'", name);
               SqlCommand cmd = new SqlCommand(sql, conn);
               int i = cmd.ExecuteNonQuery();
               conn.Close();
               return i;
           }
       }

       /// <summary>
       /// 修改为审核完成
       /// </summary>
       /// <param name="name"></param>
       /// <returns></returns>
       public int ProUptTwo(string name)
       {
           using (SqlConnection conn = new SqlConnection(Common.conn))
           {
               conn.Open();
               string sql = string.Format("update Basic_Info set Basic_State=2 where ProjectNumber='{0}'", name);
               SqlCommand cmd = new SqlCommand(sql, conn);
               int i = cmd.ExecuteNonQuery();
               conn.Close();
               return i;
           }
       }
    }
}
